/**
 * 
 */
package org.whatisjava.action.result;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.dispatcher.StrutsResultSupport;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.util.ValueStack;

/**
 * 自己定义的result_type
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 * @date 2010-2-1
 */

public class TextResult extends StrutsResultSupport {

    /**
	 * 
	 */
    private static final long serialVersionUID = 1L;
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * ActionInvocation:该对象封装了对拦截器,对result,整个...的调用过程当中的整个信息<br>
     */
    @Override
    protected void doExecute(String finalLocation, ActionInvocation invocation)
            throws Exception {
        //
        ValueStack vs = invocation.getStack();
        ActionContext ctx = invocation.getInvocationContext();

        Object value = vs.findValue(name);
        HttpServletResponse response = (HttpServletResponse) ctx
                .get(HTTP_RESPONSE);
        response.setContentType("text/plain;charset=utf-8");
        PrintWriter out = response.getWriter();

        out.print(value);
        out.flush();
        out.close();
    }
}
